/**
 * 
 */

package com.pp.admin.main.client.tab.objectpages;

import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.pp.admin.common.client.beans.Contact;
import com.pp.admin.common.client.helper.AdminFlexTable;
import com.pp.admin.common.client.helper.AdminFormTextBox;

/**
 * @author pandurang
 */
public class ContactInfo extends AdminFlexTable {

	private Contact contact = null;

	private AdminFormTextBox add1 = new AdminFormTextBox();

	private AdminFormTextBox add2 = new AdminFormTextBox();

	private AdminFormTextBox city = new AdminFormTextBox();

	private AdminFormTextBox state = new AdminFormTextBox();

	private AdminFormTextBox pin = new AdminFormTextBox();

	private AdminFormTextBox country = new AdminFormTextBox();

	static final int CONTACT_INFO_LBL_ROW = 0;

	static final int ADD1_ROW = 1;

	static final int ADD2_ROW = 2;

	static final int CITY_ROW = 3;

	static final int STATE_ROW = 4;

	static final int PIN_ROW = 5;

	static final int COUNTRY_ROW = 6;

	static final int NO_TABLE_COLS = 2;

	public ContactInfo(Contact contact) {
		this.contact = contact;
		init();
		add1.setText(contact.getAdd1());
		add2.setText(contact.getAdd2());
		city.setText(contact.getCity());
		state.setText(contact.getState());
		pin.setText(contact.getPin() + "");
		country.setText(contact.getCountry());
	}

	public ContactInfo() {
		contact = new Contact();
		init();
	}

	public void init() {

		this.setWidget(CONTACT_INFO_LBL_ROW, LABEL_COL, new Label(myConstants
				.addressinfo()
				+ " : "));
		this.setTdAttribute(CONTACT_INFO_LBL_ROW, LABEL_COL,
				AdminFlexTable.ATR_TD_COLSPAN, "" + NO_TABLE_COLS);
		this.setWidget(ADD1_ROW, LABEL_COL, new Label(myConstants.add1()
				+ " : "));
		this.getCellFormatter().setHorizontalAlignment(ADD1_ROW, LABEL_COL,
				HasHorizontalAlignment.ALIGN_RIGHT);
		this.setWidget(ADD1_ROW, FIELD_COL, add1);
		this.setWidget(ADD2_ROW, LABEL_COL, new Label(myConstants.add2()
				+ " : "));
		this.getCellFormatter().setHorizontalAlignment(ADD2_ROW, LABEL_COL,
				HasHorizontalAlignment.ALIGN_RIGHT);
		this.setWidget(ADD2_ROW, FIELD_COL, add2);
		this.setWidget(CITY_ROW, LABEL_COL, new Label(myConstants.city()
				+ " : "));
		this.getCellFormatter().setHorizontalAlignment(CITY_ROW, LABEL_COL,
				HasHorizontalAlignment.ALIGN_RIGHT);
		this.setWidget(CITY_ROW, FIELD_COL, city);
		this.setWidget(STATE_ROW, LABEL_COL, new Label(myConstants.state()
				+ " : "));
		this.getCellFormatter().setHorizontalAlignment(STATE_ROW, LABEL_COL,
				HasHorizontalAlignment.ALIGN_RIGHT);
		this.setWidget(STATE_ROW, FIELD_COL, state);
		this
				.setWidget(PIN_ROW, LABEL_COL, new Label(myConstants.pin()
						+ " : "));
		this.getCellFormatter().setHorizontalAlignment(PIN_ROW, LABEL_COL,
				HasHorizontalAlignment.ALIGN_RIGHT);
		this.setWidget(PIN_ROW, FIELD_COL, pin);
		this.setWidget(COUNTRY_ROW, LABEL_COL, new Label(myConstants.country()
				+ " : "));
		this.getCellFormatter().setHorizontalAlignment(COUNTRY_ROW, LABEL_COL,
				HasHorizontalAlignment.ALIGN_RIGHT);
		this.setWidget(COUNTRY_ROW, FIELD_COL, country);

	}

	public Contact getContact() {

		contact.setAdd1(add1.getTextBox().getText());
		contact.setAdd2(add2.getTextBox().getText());
		contact.setCity(city.getTextBox().getText());
		contact.setState(state.getTextBox().getText());
		contact.setPin(Long.parseLong(pin.getTextBox().getText().trim()));
		contact.setCountry(country.getTextBox().getText());
		return contact;
	}
}
